<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge,chrome=1">
    <meta name="author" content="程月">
    <title>轮播图</title>
    <style>
        body {
            background-color: lightblue;
        }

        .box {
            width: 520px;
            height: 280px;
            margin: 100px auto;
            position: relative;
        }

        ul {
            margin: 0;
            padding: 0;
            list-style: none;
        }

        li {
            position: absolute;
            top: 0;
            left: 0;
            display: none;
        }

        .current {
            display: block;
        }

        .yuan {
            width: 120px;
            height: 30px;
            /* margin: 0 auto; */
            /* border: 1px  solid #aaa;
        background-color: #aaa; */
            position: absolute;
            display: flex;
            justify-content: space-around;
            bottom: 30px;
            left: 200px;
        }

        section {
            width: 10px;
            height: 10px;
            border: 1px solid #aaa;
            background-color: #eee;
            border-radius: 100%;
        }

        .red {
            background-color: red;
            border: 1px solid red;
        }
    </style>
</head>

<body>
    <div class="box">
        <ul>
            <li class="current"><a href="#"><img src="img/01.jpg" alt=""></a></li>
            <li><a href="#"><img src="img/02.jpg" alt=""></a></li>
            <li><a href="#"><img src="img/03.jpg" alt=""></a></li>
            <li><a href="#"><img src="img/04.jpg" alt=""></a></li>
            <li><a href="#"><img src="img/05.jpg" alt=""></a></li>
        </ul>
        <div class="yuan">
            <section class="red a"></section>
            <section class="a"></section>
            <section class="a"></section>
            <section class="a"></section>
            <section class="a"></section>
        </div>
    </div>
</body>

</html>
<script>
    var lis = document.querySelectorAll('li');
    var sec = document.querySelectorAll('.a');

    var index = 0;
    var time = setInterval(changeImage, 1000);

    function changeImage() {
        for (var i = 0; i < lis.length; i++) {
            lis[i].className = '';
            sec[i].className = '';
        }
       
        index++;
        if (index == 5) {
            index = 0;
        }
         lis[index].className = 'current';
        sec[index].className = 'red';

    }

    for (var i = 0; i < sec.length; i++) {
        lis[i].index = i;
        sec[i].index = i;
        sec[i].onmouseover = function () {

            for (var i = 0; i < sec.length; i++) {
                lis[i].className = ' ';
                sec[i].className = ' ';
                clearInterval(time);
                // changeImage();
            }
            sec[this.index].className = 'red';
            lis[this.index].className = 'current';
        }


        sec[i].onmouseout = function () {
              index=this.index;
            time = setInterval(changeImage, 1000);
        }
    }

</script>